#!/bin/bash

source ${PTXDIST_WORKSPACE}/ptxconfig

case ${PTXCONF_ARCH_STRING} in
	arm)
		CPUVENDOR="ARM"
	;;
	i?86)
		CPUVENDOR="Intel"
	;;
	ppc)
		CPUVENDOR="PowerPC"
	;;
	sparc)
		CPUVENDOR="SPARC"
	;;
	mips)
		CPUVENDOR="MIPS"
	;;
	*)
		echo please add CPUVENDOR for PTXCONF_ARCH=${PTXCONF_ARCH_STRING} to Makefile
		exit 1
	;;
esac
cd $PTXDIST_WORKSPACE/root
echo
echo $CPUVENDOR cuckoo test

echo "1 pass (egg test)"
find . -type f -a \! -path "*share/terminfo*" -exec file {} \; | sed \
-e "s/ASCII.*/+++OK+++/" \
-e "s/Bourne.*executable/+++OK+++/" \
-e "s/empty/+++OK+++/" \
-e "s/Bourne.*text/+++OK+++/" \
-e "s/PPCBoot.*/+++OK+++/" \
-e "s/ELF.*$CPUVENDOR.*/+++OK+++/" \
-e "s/FIGlet.*/+++OK+++/" \
-e "s/python script.*/+++OK+++/" \
-e "s/Berkeley DB.*/+++OK+++/" \
-e "s/Compiled terminfo entry.*/+++OK+++/" \
-e "s/python.*byte-compiled.*/+++OK+++/" \
-e "s/data/+++OK+++/" \
-e "s/MPEG.*/+++OK+++/" \
-e "s/XML.*/+++OK+++/" \
-e "s/.*\.qpf/+++OK+++/" \
-e "s/exported SGML document text/+++OK+++/" \
-e "s/.*\.bin: $/+++OK+++/" \
    | \
grep -v "+++OK+++" | \
awk -F, '{print substr($1, 1, index($1,":"))" wrong architecture! ("$2")"}'
echo "---"

echo "2 pass (fluff up test)"
find . -type f -exec file {} \; | grep -v "\.ko" | grep -v ".*\.qpf" | grep "not stripped" | 
awk -F: '{print $1" not stripped"}'
echo "---"

echo "3 pass (in laws test)"

find . -type f -exec file {} \; | \
awk -F: -vARCH=${PTXCONF_COMPILER_PREFIX} '{if (index($2,"ELF")) print ARCH"readelf -d "$1}' | \
sh | grep "(NEEDED)" | \
awk '{gsub("\\[","");gsub("\\]","");print "if [ \"x$(find . -name "$5")\" = \"x\" ]; then echo "$5" not found ; fi"}' | \
sort -u | sh

echo "---"
